package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.MerchantPrinters;
import com.ruoyi.merchant.service.IMerchantPrintersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家打印机信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/merchant/printers")
public class MerchantPrintersController extends BaseController
{
    @Autowired
    private IMerchantPrintersService merchantPrintersService;

    /**
     * 查询商家打印机信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:printers:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantPrinters merchantPrinters)
    {
        startPage();
        List<MerchantPrinters> list = merchantPrintersService.selectMerchantPrintersList(merchantPrinters);
        return getDataTable(list);
    }

    /**
     * 导出商家打印机信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:printers:export')")
    @Log(title = "商家打印机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantPrinters merchantPrinters)
    {
        List<MerchantPrinters> list = merchantPrintersService.selectMerchantPrintersList(merchantPrinters);
        ExcelUtil<MerchantPrinters> util = new ExcelUtil<MerchantPrinters>(MerchantPrinters.class);
        util.exportExcel(response, list, "商家打印机信息数据");
    }

    /**
     * 获取商家打印机信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:printers:query')")
    @GetMapping(value = "/{printerId}")
    public AjaxResult getInfo(@PathVariable("printerId") String printerId)
    {
        return success(merchantPrintersService.selectMerchantPrintersByPrinterId(printerId));
    }

    /**
     * 新增商家打印机信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:printers:add')")
    @Log(title = "商家打印机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantPrinters merchantPrinters)
    {
        return toAjax(merchantPrintersService.insertMerchantPrinters(merchantPrinters));
    }

    /**
     * 修改商家打印机信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:printers:edit')")
    @Log(title = "商家打印机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantPrinters merchantPrinters)
    {
        return toAjax(merchantPrintersService.updateMerchantPrinters(merchantPrinters));
    }

    /**
     * 删除商家打印机信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:printers:remove')")
    @Log(title = "商家打印机信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{printerIds}")
    public AjaxResult remove(@PathVariable String[] printerIds)
    {
        return toAjax(merchantPrintersService.deleteMerchantPrintersByPrinterIds(printerIds));
    }
}
